{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/docs/notebooks/24_publish_maps.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
    "\n",
    "Uncomment the following line to install [geemap](https://geemap.org) if needed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# !pip install geemap"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2",
   "metadata": {},
   "source": [
    "To follow this tutorial, you will need to [sign up](https://datapane.com/accounts/signup/) for an account with <https://datapane.com>, then install and authenticate the `datapane` Python package. More information can be found [here](https://docs.datapane.com/tutorials/tut-getting-started). \n",
    "\n",
    "- `pip install datapane`\n",
    "- `datapane login`\n",
    "- `datapane ping`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap.foliumap as geemap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a map centered at (lat, lon).\n",
    "Map = geemap.Map(center=[40, -100], zoom=4)\n",
    "\n",
    "# Use an elevation dataset and terrain functions to create\n",
    "# a custom visualization of topography.\n",
    "\n",
    "# Load a global elevation image.\n",
    "elev = ee.Image(\"USGS/GMTED2010\")\n",
    "\n",
    "# Zoom to an area of interest.\n",
    "Map.setCenter(-121.069, 50.709, 6)\n",
    "\n",
    "# Add the elevation to the map.\n",
    "Map.addLayer(elev, {}, \"elev\")\n",
    "\n",
    "# Use the terrain algorithms to compute a hillshade with 8-bit values.\n",
    "shade = ee.Terrain.hillshade(elev)\n",
    "Map.addLayer(shade, {}, \"hillshade\", False)\n",
    "\n",
    "# Create a \"sea\" variable to be used for cartographic purposes\n",
    "sea = elev.lte(0)\n",
    "Map.addLayer(sea.mask(sea), {\"palette\": \"000022\"}, \"sea\", False)\n",
    "\n",
    "# Create a custom elevation palette from hex strings.\n",
    "elevationPalette = [\"006600\", \"002200\", \"fff700\", \"ab7634\", \"c4d0ff\", \"ffffff\"]\n",
    "# Use these visualization parameters, customized by location.\n",
    "visParams = {\"min\": 1, \"max\": 3000, \"palette\": elevationPalette}\n",
    "\n",
    "# Create a mosaic of the sea and the elevation data\n",
    "visualized = ee.ImageCollection(\n",
    "    [\n",
    "        # Mask the elevation to get only land\n",
    "        elev.mask(sea.Not()).visualize(**visParams),\n",
    "        # Use the sea mask directly to display sea.\n",
    "        sea.mask(sea).visualize(**{\"palette\": \"000022\"}),\n",
    "    ]\n",
    ").mosaic()\n",
    "\n",
    "# Note that the visualization image doesn't require visualization parameters.\n",
    "Map.addLayer(visualized, {}, \"elev palette\", False)\n",
    "\n",
    "# Convert the visualized elevation to HSV, first converting to [0, 1] data.\n",
    "hsv = visualized.divide(255).rgbToHsv()\n",
    "# Select only the hue and saturation bands.\n",
    "hs = hsv.select(0, 1)\n",
    "# Convert the hillshade to [0, 1] data, as expected by the HSV algorithm.\n",
    "v = shade.divide(255)\n",
    "# Create a visualization image by converting back to RGB from HSV.\n",
    "# Note the cast to byte in order to export the image correctly.\n",
    "rgb = hs.addBands(v).hsvToRgb().multiply(255).byte()\n",
    "Map.addLayer(rgb, {}, \"styled\")\n",
    "\n",
    "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
    "Map.addLayer(ee.Image().paint(states, 0, 2), {}, \"US States\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Display the map.\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.publish(\n",
    "    name=\"Terrain Visualization\",\n",
    "    description=\"A folium map with Earth Engine data layers\",\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
